/**
 * Thong bao nguoi choi thang hoac thua
 */
package view;
import java.awt.Frame;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

import javax.swing.ImageIcon;
import javax.swing.JDialog;
import javax.swing.JLabel;

import model.Constant;
import model.database.PlayDB;


/**
 * @author heroandtn3
 * @date Nov 4, 2012
 */
public class WinLostDlg extends JDialog {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private JLabel lbImg;
	private JLabel lbPlayOther;
	private JLabel lbTitle;
	private JLabel lbPlayAgain;
	private PlayPanel playPanel;
	private ImageIcon imgWin, imgLost, imgWinTitle, imgLostTitle;

	/**
	 * 
	 */
	public WinLostDlg(Frame owner, boolean modal) {
		// TODO Auto-generated constructor stub
		super(owner, modal);
		initImage();
		initGUI();
		setLocationRelativeTo(null);
		setUndecorated(true);
		setAlwaysOnTop(true);
		setVisible(false);
	}
	
	private void initGUI() {
		try {
			{
				getContentPane().setLayout(null);
				getContentPane().setBackground(new java.awt.Color(0,51,51));
				{
					lbImg = new JLabel();
					getContentPane().add(lbImg);
					lbImg.setBounds(46, 25, 300, 216);
				}
				{
					lbPlayAgain = new MyLabelButton(Constant.BUTTON_DIR + "playagain", "Replay this level", false);
					getContentPane().add(lbPlayAgain);
					lbPlayAgain.setBounds(461, 193, 48, 48);
					lbPlayAgain.addMouseListener(new MouseAdapter() {
						public void mouseClicked(MouseEvent evt) {
							//TODO add your code for lbPlayAgain.mouseClicked
							playPanel.getPlaying().setScore(playPanel.getScore());
							PlayDB pDB = new PlayDB();
							pDB.insertPlay(playPanel.getPlaying());
							playPanel.resetGame();
							playPanel.initGame();
							setVisible(false);
						}
					});
				}
				{
					lbPlayOther = new MyLabelButton(Constant.BUTTON_DIR + "playother", "Back to home to play other maps", false);
					getContentPane().add(lbPlayOther);
					lbPlayOther.setBounds(631, 193, 48, 48);
					lbPlayOther.addMouseListener(new MouseAdapter() {
						public void mouseClicked(MouseEvent evt) {
							//TODO add your code for lbPlayOther.mouseClicked
							setVisible(false);
							playPanel.getPlaying().setScore(playPanel.getScore());
							PlayDB pDB = new PlayDB();
							pDB.insertPlay(playPanel.getPlaying());
							playPanel.resetGame();
							playPanel.getMainPanel().switchPanel(UserHomePanel.KEY);
						}
					});
				}
				{
					lbTitle = new JLabel();
					getContentPane().add(lbTitle);
					lbTitle.setBounds(427, 25, 310, 105);
				}
			}
			{
				this.setSize(900, 300);
			}
		} catch(Exception e) {
			//e.printStackTrace();
		}
	}
	
	private void initImage() {
		imgWin = new ImageIcon(Constant.BG_DIR + "win");
		imgLost = new ImageIcon(Constant.BG_DIR + "lost");
		imgWinTitle = new ImageIcon(Constant.BG_DIR + "win-title");
		imgLostTitle = new ImageIcon(Constant.BG_DIR + "lost-title");
	}
	
	public void setWin(boolean win) {
		if (win) {
			lbImg.setIcon(imgWin);
			lbTitle.setIcon(imgWinTitle);
		} else {
			lbImg.setIcon(imgLost);
			lbTitle.setIcon(imgLostTitle);
		}
		
	}

	/**
	 * @return the playPanel
	 */
	public PlayPanel getPlayPanel() {
		return playPanel;
	}

	/**
	 * @param playPanel the playPanel to set
	 */
	public void setPlayPanel(PlayPanel playPanel) {
		this.playPanel = playPanel;
	}

}
